#ifndef frm_control_TSplitter_H
#define frm_control_TSplitter_H

#include "frm_control_TPanel.h"

namespace frm { namespace control {

////////////////////////////////////////////////////////////////////////////////

struct TSplitter : public TPanel
{
  enum ESplit { Vert = 0,Horz = 1,Both = 2 };
  //
  struct TStyle : public frm::TStyle
  {
    svl_Type(frm::TStyle)
    TPanel::TStyle Normal,Down;
    int            Weight;
    //
    virtual ESplit GetESplit()=0;
    //
    virtual void SetFromParent(frm::TStyle *Parent);
    virtual svl::TInfoParam AddInfoTo(svl::TInfoParam Info);
  };
  struct TStyleVert : public TStyle
  {
    void SetDefault();
    //
    virtual ESplit GetESplit() { return Vert;}
  };
  struct TStyleHorz : public TStyle
  {
    void SetDefault();
    //
    virtual ESplit GetESplit() { return Horz;}
  };
  struct TStyleBoth : public TStyle
  {
    void SetDefault();
    //
    virtual ESplit GetESplit() { return Both;}
  };
  //////////////
  struct TStyles
  {
    TStyleVert Vert;
    TStyleHorz Horz;
    TStyleBoth Both;
    //
    TStyles() 
    { 
      s[TSplitter::Vert] = &Vert; Vert.SetDefault();
      s[TSplitter::Horz] = &Horz; Horz.SetDefault();
      s[TSplitter::Both] = &Both; Both.SetDefault();
    }
    //
    TStyle &Get(ESplit V) { return *s[V];}
    
  private:
    TStyle *s[3];
  };
  static TStyles &DefaultStyles() { static TStyles Styles; return Styles; }
  
public:                                                 
  TSplitter(TWindow &Window,ESplit Split,TPanel *CResizePrev = NULL);
  
public:  
  svl_Type(TPanel);
 ~TSplitter();
  //
  TSplitter &SetStyle(TStyle &V);
  //
  ESplit GetESplit() { return eSplit;}
  //
  void SetMinSize(int V = 50) { minSize = V;}
  void SetSize   (int V = 20);
  //
  void SetCResizePrev(TPanel *V) { cResizePrev = V;}
  void SetCResizeNext(TPanel *V) { cResizeNext = V;}
  //
  virtual void TComponent_Mouse(TMouse Mouse);
  virtual bool TComponent_TransparentForFocus() { return false;}
  virtual void TComponent_InheritStyleFrom(TTableOfStyles &ParentStyles);

private:
  void Init(ESplit Split,TPanel *CResizePrev);
  //
  struct TParam : public frm::TDebug
  {
    grf::TPoint PtBegin;
    grf::TSize  SizeBeginPrev,SizeBeginNext;
  };
  struct TSplit : public svl::TSet { svlTSet(TSplit,ESplit); };
  TParam *param;
  TSplit  split;
  ESplit  eSplit;
  //
  TPanel *cResizePrev,*cResizeNext;
  int minSize;
  TStyle *style;    
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TSplitterVert : public TSplitter
{
  struct TStyle : public TStyleVert
  {
    svl_Type(TStyleVert)
  };
  //
  svl_Type(TSplitter);
  TSplitterVert(TWindow &Window,TPanel *CResizePrev = NULL) : TSplitter(Window  ,Vert,CResizePrev) {}
  //
  TSplitterVert &SetStyle(TStyle &V) { TSplitter::SetStyle(V); return *this;} 
  //
  virtual void TComponent_InheritStyleFrom(TTableOfStyles &ParentStyles);

private:
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TSplitterHorz : public TSplitter
{
  struct TStyle : public TStyleHorz
  {
    svl_Type(TStyleHorz)
  };
  //
  svl_Type(TSplitter);
  TSplitterHorz(TWindow &Window,TPanel *CResizePrev = NULL) : TSplitter(Window  ,Horz,CResizePrev) {}
  //
  TSplitterHorz &SetStyle(TStyle &V) { TSplitter::SetStyle(V); return *this;} 
  //
  virtual void TComponent_InheritStyleFrom(TTableOfStyles &ParentStyles);

private:
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TSplitterBoth : public TSplitter
{
  struct TStyle : public TStyleBoth
  {
    svl_Type(TStyleBoth)
  };
  //
  TSplitterBoth(TWindow &Window,TPanel *CResizePrev = NULL) : TSplitter(Window,Both,CResizePrev) {}
  //
  TSplitterBoth &SetStyle(TStyle &V) { TSplitter::SetStyle(V); return *this;} 
  //
  virtual void TComponent_InheritStyleFrom(TTableOfStyles &ParentStyles);

private:
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}}

#endif
